<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">分布式任务调度</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>分布式任务调度&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">执行器管理</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
      <div class="row mbl">
			<div class="col-lg-12">
				<div class="tb-group-actions pull-left">
					<button class="btn btn-sm btn-primary" onclick="addAndEdit('0')">新增执行器 </button>
					<button class="btn btn-sm btn-blue">调度中心OnLine机器：</button>
					<span id="addresslist"></span>
						
			</div>
		</div>
       </div>
 
      <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
            <thead>
                <tr>                 
                    <th >排序</th>
                    <th >APPName</th>
                    <th >名称</th>
                    <th >注册方式</th>
                    <th >OnLine 机器</th>
                    <th >可操作</th>
                </tr>
            </thead>
            <tbody id="newspaperls"></tbody>
        </table>
		<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		</div>
        <div id="page1" style="text-align: center; margin-top: 20px;"></div>
    </div>
                     
    <!--END CONTENT-->
    </div>

  
<?} ?>
<script>
 var cur;var id;
$(function(){
    cur=1;
	list1(cur);
});
function get(){
  list1(cur);
}
function getlay() {  
    return id;
}
function list1(curr) {
	$.getJSON("./xxljob_group_pageList.do",
	{
		//page : curr || 1,
		//pageNumber:$("#pageNumber").val(),
		//queryParams:$("#queryParams").val(),
        //text:$("#text").val(),
	},
	function(res) {
	//此处仅仅是为了演示变化的内容
		var str = "";
		var addresses=""; 
		if(res.listsize>0){
			$("#dataNull").hide();
		}else{
			$("#dataNull").show();
		}
		$("#newspaperls").html("")
		$("#addresslist").html("")
		for ( var i = 0; i < res.listsize; i++) {
			str += "<tr><td align=\"center\"> "
					+ res.list[i].order
					+ "</td><td> <label >"
					+ res.list[i].appName
					+ "</label></td><td><label >"
					+ res.list[i].title
					+ "</label></td><td><label >"
					+ (res.list[i].addressType=="0"?"自动注入":"手动注入")
					+ "</label></td><td>";
					if(res.list[i].registryList==""){
						str += "<span class=\"badge badge-green\">"+"</span>";
					}else{
						var address = eval(res.list[i].registryList);
						for(var j= 0; j< address.length;j++){
							str += "<span class=\"badge badge-green\">"+address[j]+"</span>";
						}
					}
					str += "</td><td>"
					+"	<button type=\"button\" class=\"btn btn-yellow btn-xs\" onclick=\"addAndEdit("+res.list[i].id+")\">编辑</button>"
					+ "	<button type=\"button\" class=\"btn btn-red btn-xs\" onclick=\"remove1("+res.list[i].id+")\">删除</button>"
					+ "</td></tr>";
		}
		if(res.adminAddressList!=null || res.adminAddressList!=undefined ||adminAddressList!=''){
			var addresslist = eval(res.adminAddressList);
			for(var i=0;i<addresslist.length;i++){
				addresses += "<button type=\"button\" class=\"btn btn-blue btn-outlined\">"+addresslist[i]+"</button>";
			}
		}
		$("#addresslist").append(addresses);
		$("#newspaperls").append(str);
        document.getElementById('pageSize').innerHTML=res.listsize;
		laypage({
			cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
			pages : res.pageSize, //总页数
			skip : true, //是否开启跳页
			skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
			curr : curr || 1,
			last: res.pageSize,
			groups : 6,//连续显示分页数
			jump : function(obj, first) { //触发分页后的回调
				if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
					list1(obj.curr);
					var curr = obj.curr;
					curr = obj.curr;
				}
			}
		});
	});
}
function addAndEdit(lid) {
	id=lid;
	layer.open({
		type : 2,
		area : [ '600px', '480px' ],
		scrollbar : false,
		shadeClose : true,
		fix : true, //不固定
		title : "新增执行器",
		//maxmin : true,  
		skin : 'layui-layer-rim', //加上边框
		btn : [ "保存 ", "关闭" ],
		content : [ "xxl-job-group-add.html", "no" ],
		yes : function(index, layer) {
			var iframeWin = parent.window[layer.find("iframe")[0]["name"]];
			iframeWin.Save();
		},
		cancel : function(index) {
		}

	});
}
//删除			
function remove1(id) {
	layer.confirm("是否确认删除？", {
		  btn: ["确定","删除"] //按钮
		}, function(){
			$.ajax({
				type : "post",
				url : "./xxljob_group_remove.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data.result=="ok"){
						layer.msg("删除成功！", {icon: 6});
					}else if(data.result=="no"){
						layer.msg("删除失败！", {icon: 5});
					}else{
						layer.msg(data.result, {icon: 5});
					}
					get();
				},
				error : function(data) {
					layer.msg("请求失败！", {icon: 2});
				}
			});
		}, function(){
	});
	
}
//glue编辑
function glue(lid){
	id=lid;
	layer.open({
		type : 2,
		area : [ '800px', '480px' ],
		scrollbar : false,
		shadeClose : true,
		fix : true, //不固定
		title : "WEBIDE			任务:"+id,
		//maxmin : true,  
		skin : 'layui-layer-rim', //加上边框
		btn : [ "保存 ", "关闭" ],
		content : [ "xxl-job-code-edit.html", "no" ],
		yes : function(index, layer) {
			var iframeWin = parent.window[layer.find("iframe")[0]["name"]];
			iframeWin.Save();
		},
		cancel : function(index) {
		}

	});
}
</script>